import request from '@/utils/request'
import type { SubmitOrder, OrderResponseData, Qrcode, PayResult, CertationTypeResponseData, UserParams, UserOrderInfoResponseData, AllUserResponseData, AllOrderStateResponseData, AddOrUpdateUser } from './type'
enum API {
    // 提交订单，获取订单号码
    SUBMITORDER_URL = '/order/orderlnfo/auth/submitOrder/',
    // 获取订单详情的数据
    GETORDERINFO_URL = '/order/orderlnfo/auth/getOrderlnfo/',
    // 取消订单
    ORDERCANCEL_API = '/order/orderInfo/auth/cancelOrder/',
    // 获取支付订单二维码
    QRCODE_URL = '/order/orderlnfo/auth/getOrderlnfo/',
    // 查询订单支付结果
    PAYRESULT_URL = '/order/weixin/queryPayStatus/',
    // 获取会员信息
    USERINFO_URL = '/user/auth/getUserInfo',
    // 获取证件类型
    CERTIFICATIONTYPE_URL = '/cmn/dict/findByDictCode/',
    // 会员认证
    USERCERTATION_URL = '/user/auth/userAuah',
    // 获取用户订单的数据
    USERORDERINFO_URL = '/order/orderlnfo/auth/',
    // 获取全部就诊人
    ALLUSER_URL = '/user/patient/auth/findAll',
    // 获取所有订单状态
    ORDERSTATE_URL = '/order/orderlnfo/auth/getStatusList',
    // 获取城市的数据
    CITY_URL = '/cmn/dict/findByParentId/',
    // 新增就诊人
    ADDUSER_URL = '/user/patient/auth/save',
    // 更新就诊人
    UPDATEUSER_URL = '/user/patient/auth/update',
    // 删除就诊人
    DELETEUSER_URL = '/user/patient/auth/remove/'

}
// 提交订单
export const reqSubmitOrder = (hoscode: string, scheduleId: string, patientId: number) => {
    return request.post<any, SubmitOrder>(API.SUBMITORDER_URL + `${hoscode}/${scheduleId}/${patientId}`)
}
// 获取订单详情的数据
export const reqOrderInfo = (id: string) => {
    return request.get<any, OrderResponseData>(API.GETORDERINFO_URL + id)
}
// 取消订单
export const reqCancelOrder = (id: string) => {
    return request.get<any, any>(API.ORDERCANCEL_API + id)
}
// 获取支付二维码
export const reqQrcode = (orderId: string) => {
    return request.get<any, Qrcode>(API.QRCODE_URL + orderId)
}
// 查询订单支付结果
export const reqPayResult = (orderId: string) => {
    return request.get<any, PayResult>(API.PAYRESULT_URL + orderId)
}
// 获取会员信息
export const reqUserInfo = () => {
    return request.get<any, any>(API.USERINFO_URL)
}
// 获取证件类型
export const reqCertificationType = () => {
    return request.get<any, CertationTypeResponseData>(API.CERTIFICATIONTYPE_URL + 'certificatesType')
}
// 会员认证
export const userCertation = (data: UserParams) => {
    return request.post<any, any>(API.USERCERTATION_URL, data)
}
// 获取用户订单的数据
export const reqUserOrderInfo = (page: number, limit: number, patientId: string, orderStatus: string) => {
    return request.get<any, UserOrderInfoResponseData>(API.USERORDERINFO_URL + `${page}/${limit}?patientId=${patientId}&orderStatus=${orderStatus}`)
}
//获取全部就诊人的信息
export const reqAllUser = () => {
    return request.get<any, AllUserResponseData>(API.ALLUSER_URL);
}

//获取全部订单的接口
export const reqOrderState = () => {
    return request.get<any, AllOrderStateResponseData>(API.ORDERSTATE_URL);
}
// 获取城市的数据
export const reqCity = (parentId: string) => {
    return request.get<any, any>(API.CITY_URL + parentId)
}

// 新增与修改就诊人
export const reqAddOrUpdateUser = (data: AddOrUpdateUser) => {
    // 有id就是修改 否则是新增
    if (data.id) {
        return request.put<any, any>(API.UPDATEUSER_URL, data)
    } else {
        return request.post<any, any>(API.ADDUSER_URL, data)
    }
}
// 删除就诊人
export const reqRemoveUser = (id: number) => {
    return request.delete<any, any>(API.DELETEUSER_URL + id)
}